3. bottle filling and capping machine 3

因此,在本视频中,我们将开始编写传送站的代码。
So in this video, we will start writing the code for the conveyor station.

实际上,我冒昧地在传送站中使用了我们在其他项目的其他视频中使用的实际骨架。
I actually took the liberty to right here in the conveyor station, the actual skeleton that we have been using in the other videos for the other project.

所以这实际上是我们之前在每个车站都会做的事情,我们在这里也可以使用它。
So this is actually something that we will we are doing in every station station before, and we can use it over here as well.

我将介绍它,以便您实际上可以暂停并自己复制它,或者您可以从上一个视频、上一个项目中复制它。
I will run through it so you can actually pause and copy it on your own or you can copy it from the previous video, previous project.

但这是我们状态机的开始,只有尚未编写的实际状态,其中包括管理紧急情况的部分、用于停止的部分和用于旧的部分。
But here is this the beginning of our state machine with only with no actual state already written, with the part where we manage the emergency, the part for the stop and the part for the old.

最后一项是关于站态输出管理。
And the last one is about the station state output management.

所以这是我们在所有电台中添加的内容,我们实际上可以将其用作我们电台的模板。
So this is something that we add in all the stations and we can actually use it as a template for our station.

好的,从这里开始,我们需要为我们的对话编写一段代码。
OK, so starting from this, we need to write a code for our conversation.

让我在这里打开它。
Let me open it here.

打开右侧的可视化。
Open the visualization here on the right.

所以实际上。
So actually.

让我们从状态零开始。
Let's start from state zero in our state zero.

我们需要这个对话能够管理 feed 中的产品。
We need this conversation needs to be the one that manages the products in feed enable.

所以我们现在在这里,我们的禁用状态产品和提要启用需要等于 false。
So here we are right now, our disabled state that products and feed enable needs to be equal to false.

如果我们收到启动请求。
And if we receive a start requests.

因此,如果他们开始而不是停止,而不是紧急情况,也不会保持。
So if they start and not then stop and not emergency and not hold.

这对我们来说是相当标准的。
This is quite standard for us.

然后我们然后。
And then we then.

我们需要这个在状态到另一个状态等于10,好的,在状态10。
We need this at the state to another one state equal to 10, OK, in state 10.

那么,我们需要做什么呢?
Well, what do we need to do?

此外,我们需要实际启用通用设备功能块。
Also, we need to actually enable the generic devices function blocks.

所以这里我们需要为该站的所有通用设备进行编写。
So here we need to write for all the generic devices of the station.

我们需要将设备命令设置为零。
We need to set the device command equal to zero.

因此,我们拥有能够启用与 Troon 相同的通用设备的传送设备。
So we have the conveyer device that enables to enable generic device that should be equal to Troon.

我们有上限。
We have the capping.

抱歉,从感觉设备开始,任何通用设备都应设置为 true,即复制并粘贴这部分。
Sorry, the start from the feeling device that any generic device that shall be set equal to true, that's copy and paste this part.

然后我们有封盖运动装置,抱歉,还有封盖运动装置和封盖装置。
Then we have the capping movement device sorry, and capping movement device and the capping device.

这里我们应该拥有所有启用的通用设备、设备的输入等,然后我们可以进入新的状态。
Here we should have all the enabled generic devices, the input of our devices, etc., and then we can move on to a new state.

在这里,让我们想想我们需要做什么。
Here, let's think of what we need to do.

我们实际上需要移动传送带。
We need actually to move the conveyor.

只要有一些产品。
Only if there are some products.

到车站,所以不是到车站,而是到传送带本身。
Onto the stations, so the not not onto the station, but on the conveyor itself.

因此我们需要跟踪传送带上有多少产品。
So we need to keep track of how many products are on the conveyor.

因此,我们可以在这里编写一些代码来跟踪产品,因此我们需要一些蓖麻毒素触发器和完全触发器,这意味着每当我们在此传感器上检测到树脂触发器时,就意味着有新产品。
So we can right over here some code to keep track of the products, so we will need to have some ricin trigger and fully trigger, it means that whenever we detect a resin trigger on this sensor, it means that there is a new product.

当我们检测到该传感器上有下落触发器时,这意味着产品已离开传送带。
And when we detect a falling trigger on this sensor, it means that the product has left the conveyor.

使用这些信息,我们实际上可以知道站点上有多少产品。
Using this information, we are actually able to know how many products are there on the stations.

所以在这里。
So here.

我可以添加一些树脂触发器,所以我将其称为我们的 Twigg,嗯,我们在启动传送带上的触发产品。
I can add some resin triggers, so I would call this our Twigg, um, our trig product on start conveyor.

我将写一个无花果,它是处于拾取位置的产品,并且我们还需要另外两个传感器的另一个触发器,以便知道产品何时到达该站。
I will write a fig that is a product on pick up position and also we would need another trigger for the other two sensors in order to know when the products when a product has reached that station.

因此,我还将创建另外三个产品,称为加油站产品和我们的三个产品称为封盖站产品。
So I will also create another three that would call product on filling station and our three product on capping station.

因此,我们实际上可以将对这个函数块的调用放在状态机之上,所以让我们简单地放置让我们从第一个开始的三个功能块。
So we can actually place the calls to this function blocks above the state machine, so let's simply place are to let's right our three start from the first one.

产品并启动传送带。
Product and start conveyor.

第二个。
The second one.

动脉而不是加油站。
Artery rather than filling station.

正确的产品开盖站,最后一个将是分解位置上的F3产品。
The right product uncapping station and the last one will be the F3 product on decomposition position.

所以这里我们有三四次调用这个函数,看起来更少连接相应的 clucky 输入。
So here we have three with four calls to this function, looks less connect the corresponding clucky input.

所以对于第一个,我们有产品。
So for the first one, we have the product.

在传送开始传感器上传送时,第二个是灌装站传感器上的产品,第三个是产品开盖站传感器,然后我们将产品放在拾取位置。
On convey on Convey Your Start sensor, the second one is product on filling station sensor, the third one is product uncapping station sensor and then we have the product on pick up position.

抱歉,忘记在这里了,捡起来。
Sorry, forget it here, pick up.

所以我们现在实际上能够检测到这三个传感器的上升触发、上升广告以及该传感器的后续触发。
So we are actually able to detect now the rising triggers, rising ads of these three sensors and the following trigger of this sensor.

因此,我们需要一个变量来跟踪站点上有多少产品。
So we need to have a variable that will be used to keep track of how many products are there on the station.

因此,我将传送带上的产品数量称为无符号整数。
So I would call this number of products on conveyor that will be an unsigned integer.

在这里,我们可以说,如果启动传送带上有另一个触发产品,则该提示意味着这里有一个上升触发器。
And over here we can say that if there is another trig product on start conveyor, that cue means that there is a rising trigger here.

产品数量应增加一种。
The number of products should be increased by one.

因此,这里,传送带上的产品数量应等于传送带上的产品数量加一。
So here, number of products on conveyor should be equal to number of products on conveyor plus one.

相反,如果我们在挑选排队位置时收到了整整三个产品,那么传送带上的产品数量应该减少一个。
And if instead we receive one full three product on pick a position that queue, then the number of products on the conveyor should decrease by one.

好的,所以在这里,我们写一个评论,说这是产品帐户管理,为什么我们不进入状态呢?
OK, so here, let's write a comment saying that this is the product account management and why don't we get here in state?

我们实际上应该从这里开始,等待产品,等待产品,在这里我们应该将产品设置在 Feed Nable 执行器中。
We should actually start by this is where we wait for products, wait for products, and here we should set the products in Feed Nable actuators.

实际上,当传送带上有一些产品时,我们需要开始移动传送带。
And we need to actually we will need to start moving the conveyor when we have some products on the conveyor.

因此,如果传送带上的产品数量大于零,那么我们将转移到另一个状态 20,而不是 20。
So if there is the number of products on conveyor bigger than zero, then we shall move to another state state 20, instead 20.

我们需要实际启动传送带。
We need to actually start the conveyor.

所以这里我就对了。
So here I will right.

开始移动传送带。
To start moving conveyor.

所以我会在这里骑行。
So here I will ride.

传送该设备。
Conveyor that device.

因此它可以是您的设备,该设备命令应等于 true,我们将等待设备启用。
So it can be your device, that device command should be equal to true, and we will wait for the device to be enabled.

因此,如果传送您的设备,该设备状态等于启用,那么我们将转到等于 30 的另一个状态。
So if conveyer your device, that device state is equal to enable, then we will move on to another state state equal to 30.

好的。
OK.

这样,我们就在Sturdee和。
So in this way, we are in Sturdee and.

传送带正在移动。
The conveyor is moving.

我们需要继续移动传送带,直到检测到产品。
We need to keep moving the conveyor until we detect a product.

位于加油站下方或封盖站下方。
Either below the filling station or below the capping station.

所以这里是状态 30。
So here in state 30.

我们将在车站下方等待产品,如果我们可以在这里骑行。
We will wait for products below the stations and here we can ride if.

是的,如果我们的 Twigg 产品在灌装站上,我们会写 Q 表示新产品已到达灌装站或新产品已到达封盖站。
Yeah, we will write if our Twigg product on filling station that Q Meaning that a new product has reached the filling station or a new product has reached the capping station.

问:然后我们需要停止传送带,所以让我们骑到这里的传送带设备,该设备可以而且应该设置为。
Q Then we need to stop the conveyor, so let's ride over here conveyer device, that device can and should be set to.

为了立即做出反应,我们先进入这里,然后进入状态 40,状态 40 是我们等待传送带停止的状态。
In order to react instantly, let's place to come and come in here and let's move on to state 40, state 40 is what is the one in which we wait for the conveyor to stop.

因此,请等待传送带停止。
So wait for conveyor to stop.

那么如果有输送装置的话。
So if the conveyor device that.

状态等于disabled,disabled,那么我们实际上就可以进入状态50了。
The state is equal to disabled, disabled, then we can actually move on to state 50.

好的。
OK.

因此,在状态 50 中,我们可能在灌装站或封盖站下方有一些产品,我们需要为它们处理不同操作的 Sath。
So here in state 50, we may have some products below either the filling station or the capping station, and we need to handle Sath of different operations for both of them.

所以这是相当棘手的,也是有可能的。
So this is quite tricky and it is a possibility.

实际上,在自动化和这种状态下,这种情况经常发生。
It actually happens a lot in automation and in this state.

我们需要构建一个嵌套状态机。
We need to build a nested state machine.

所以我们需要这样做。
So this will be called for us.

我们的处理状态是所有站都可以并行或不并行工作的状态,我们将看到如何并行工作,这将是一个多层嵌套的 FSM 有限状态机。
Our processing state is the one in which all the stations may work in parallel or not, and we will see how and this will be a multi nested FSM finite state machine.

所以我们实际上需要在状态机中编写状态机。
So we actually need to write a state machine within a state machine.

所以我们需要添加一些新的变量,加油站和封盖站的逊尼派状态变量。
So we need to add some new variables, Sunni state variables for the filling station and the capping station.

因此,在这里我们创建一个无符号整数形式的感觉状态和一个无符号整数形式的上限状态。
So here we create a feeling state as an unsigned integer and a capping state as an unsigned integer.

在这里,我将骑行到 50 州内的不同状态机。
And over here, I will ride to different state machines within the state 50.

所以我们到了。
So here we are.

我将编写你正在加油站的状态机。
I will write the you're filling station state machine.

下面就是。
And down here will be the.

封盖站,状态机。
Capping station, state machine.

让我们从这里开始,尝试一下案例填充站,对于我们来说,让我们使用它。
And let's start here for the case and try the case case filling station, a state of and for us, let's use this.

这种表示法表示欧元是起始状态,100 是芬兰状态,因此意味着我们处于零状态。
This notation saying that the euro is the start state and 100 is the Finnish state, so it means that we are in zero.

我们刚刚开始所有操作,相反,当我们处于状态 100 时,我们已经完成了灌装站、灌装操作,并且封盖站也需要进行同样的操作。
We are just starting all the operations and instead, when we are in state 100 that we have finished the filling station, the filling operation, and the same needs to happen for the capping station.

因此,零的案例上限状态将是我们开始的状态。
So case capping state of our zero will be the state in which we start.

因此,开始状态和 100 将是我们结束芬兰状态的状态。
So start state and 100 will be the state in which we end the Finnish state.

所以实际上,当我们处于状态 50 时,从远处看,这两个状态是状态机将运行,如果感觉状态和上限状态都达到 100,我们实际上需要退出该状态。
So actually, looking at from far away when we are in state 50, these two states are state machines will be running and we actually need to get out from this state if both the feeling state and the capping state reached 100.

因此,如果失败状态等于 100,上限状态等于 100,则意味着这两个操作都已完成,我们实际上可以继续使用状态机,比方说,转到另一个状态,目前为 60。
So if the failing state is equal to 100 and the capping state is equal to 100, it means that both operations are finished and we can actually move on with our state machine, let's say, to another state, 60 for now.

那么我们来思考一下加油站需要做什么,加盖站需要做什么。
So let's think about what the filling station needs to do and what the capping station needs to do.

所以。
So.

对于加油站来说,每当加油站内有产品时,我们就需要激活感觉装置。
For the filling station, whenever there is a product within the filling station, we need to activate the feeling device.

所以我们确实有。
So we actually had.

我们这里实际上有一个传感器,然后我们需要等待一段时间才能将瓶子装满,我们实际上说的时间是一秒钟。
We actually have a sensor here and then we need to wait for some time in order for the bottle to be filled, and we actually said that the time was one second.

因此,为了做到这一点,我们需要一个 Tionne。
So in order to do this, we need a Tionne.

所以我称之为基奥根感觉。
So I would call this Keogan feeling.

因此,让我们从头开始,在状态零状态下,我们需要激活副指挥官应该通过的感觉装置的感觉装置。
So let's start from the from the beginning here in state state zero, we will need to activate the feeling device of feeling device that the vice commander should be set through.

我们需要等待感知装置启用。
And we need to wait for the feeling device to be enabled.

因此,如果任何设备的设备状态等于已启用,则较少更改状态即可感受到。
So if any device that device state is equal to enabled less change state get to feeling.

状态等于 10。
State equal to 10.

您需要非常小心,呃,使用正确的状态变量,因为如果您编写状态,您实际上会造成很多混乱,并且会给您的机器带来非常糟糕的操作。
You need to be very careful on on, uh, using the correct state variable, because if you write state, you actually create a lot of mess and a really bad operation for your machine.

因此,当我们转向国家时,我们听说我们需要真正等待,等待感觉,我们可以在这里启动联合国。
So when we move to state, then we hear we need to actually wait, wait for feeling and we can start the theUN over here.

所以达里恩,你的感觉应该等于真实。
So your turn your feeling, Darrien, should be equal to true.

让我们充分感受一下,嗯,泥炭味。
And let's a ton of feeling that, uh, peaty.

让我们为此创建一个变量。
Let's create a variable for this.

我会把这个时间称为感觉,并将称为一生,我们可以在这里初始化为一秒钟。
I would call this time for feeling and will be called for a lifetime that we can initialize here to one second.

时间将会被填满。
And the time will be filling time.

所以只要你有需要,你就想看到。
So whenever you need, you want to see the.

很抱歉,时间感觉。
So sorry, time feeling.

我们实际上可以称之为填充时间,更好的填充时间。
We can actually call it filling time, it's better filling time.

填充时间,所以每当你需要改变这个时间时,你可以简单地改变变量,而不需要看这个。
Filling time, so whenever you need to change this time, you can simply change the variable and you do not need to look at this.

我不需要在代码中查找您所写时间的位置。
I will not need to look in the code to wherever you wrote the time.

因此,让我们在此处添加对计时器的调用。
So let's add the call for the timer here.

所以这很抱歉。
So this sorry.

我们称之为,呃,计时器填充。
Let's call this, uh, timer filling.

是关于。
It's about.

所以我们在这里称之为这里。
So here we call this here.

时间感觉并设置了遗憾,不是遗憾,遗憾是设置为变量,所以这里我就简单地在这里调用它,好吗?
Time feeling and set the pity, not sorry, the pity is set as a variable, so here I will simply call this here, OK?

所以在 10 点继续,我们需要等待感觉结束,所以如果时间感觉很热,那么我们需要重置计时器计时器感觉应该设置达里恩。
So moving on in 10, we need to wait for the feeling to end, so if time are feeling the heat, then we need to reset the timer timer feeling Darrien should be set.

虚假团结也重置。
False unity also reset.

定时器状态为零。
The timer is state zero.

这需要发生,因为如果出现问题,他和你切换并且你在没有菲奥南完成的情况下从这种状态移动,它不会被重置。
And this needs to happen because if something goes wrong, he and you switch and you move from this state without the Fionan finishing, it won't be reset.

因此,每当你是计时器时,你都需要研究一下这一点。
So whenever you are a timer, you need to look into this.

所以每当我们完成填充时,我们就可以到达另一个状态。
So whenever we have finished filling, we you can get to another state.

因此,感觉状态等于 20,并且在状态 20 中,这将是我们需要停止感觉执行器的情况。
So feeling state equal to 20 and in state 20, this will be the we need to stop the feeling actuators.

所以停止感觉吧。
So stop feeling.

在这里,我们实际上将与此相反,因此,如果设备失败,该设备命令应该设置一个错误的感觉设备,抱歉,如果感觉设备,该设备状态等于禁用,那么我们可以获得感觉状态 100,因为我们是实际上我们在这里完成了所有需要做的事情。
And here we will right the opposite of this actually, so failing device, that device command should be set a false feeling device that sorry if feeling device, that device state is equal to disabled, then we can get the feeling state 100 because we are actually finished all the things that we needed to do here.

好的,这是一个用于填充的简单状态机。
OK, so this is a simple state machine for the filling.

然后我们需要在封顶之前做类似的事情。
Then we need to do a similar thing before the capping.

所以在这里,我们会的。
So over here, we will.

需要。
Need to.

首先,我们需要开始向下移动封盖装置。
First, we need to start moving down the capping device.

当我们这样做时,我们需要开始。
And while we do so, we need to start.

船长必须同时旋转,因此这里我们需要启用两个设备,即封盖设备,该设备可以而且应该设置为通过封盖运动设备。
The the captain had to rotate at the same time, so here we need to enable both of our devices so capping device, that device can and should be set to through capping movement device.

该设备也可以而且应该设置为直通。
The device can and should be set to through as well if.

我们的两台设备都是。
Our both of our devices are.

并启用,这意味着柜子正在旋转,我们到达了底部。
And enabled, so this means that the cabinet is rotating and we reached the bottom.

因此,如果封盖设备,该设备状态等于启用,并且封盖移动设备,该设备状态等于启用,那么这意味着。
So if capping device, that device state is equal to enabled and capping movement device, that device state is equal to enabled, then it means that.

我们可以得到另一个等于 10 的状态上限。
We can get to another state capping state equal to 10.

所以实际上,我在通用设备调用中犯了一个小错误,因为我本打算将这次作为封盖时间,但实际上这是封盖头需要启动的时间。
So actually, I made a small mistake here in the generic devices call, and because I intended this time for the as the capping time, but it is actually the time that the capping head needs to start.

移动所以它可以很小。
Moving so it can be quite small.

没错,零点一秒,现在在传送站,我们实际上需要另一个计时器来进行封盖。
That's right, zero point one seconds and over here in the conveyor station right now, we need to actually have another timer for the capping.

因此,让我们在这里创建一个计时器上限。
So let's create here a timer capping.

这也将是一个巨大的数字。
That will be a huge one as well.

让我们添加一个上限时间。
And let's add a capping time.

我们需要一个初始化为半秒的时间变量。
There will be a time variable initialized to half a second that we need.

正如我们之前所做的那样,让我们​​在状态中启动计时器。
So as we did before here, let's start the timer in the state.

因此,计时器上限范围应等于真正的计时器上限。
So, timer, capping the range should be equal to true timer capping.

这应该等于上限时间。
That should be equal to the capping time.

然后继续站在这里,我们需要等待封顶时间。
And moving on to stand here, we need to wait for the capping time.

所以等等。
So wait.

限制时间将是我们的评论。
Capping time will be our comment.

在本季度的这一部分,我们将等待计时器的上限。
And in this part of the quarter we will wait for the timer capping that.

问。
Q.

如果限制提示的计时器到达,计时器拍手 Ian 应该等于下降,我们将移动到另一个状态上限等于 20。
And if the timer capping the cue arrives, timer clapping that Ian should become equal to falls and we shall move to another state capping state equal to 20.

再次,我们需要看看。
Again, we need to look.

进入,嗯,禁用这个计时器,所以也在状态零的开头复制这行代码。
Into, um, disabling this timer, so copying this line of code at the beginning in the States zero as well.

因此,在这里我们禁用了两个计时器,然后,我们需要执行与状态零时相反的操作。
So here we disabled both timers and then after this, we need to do the opposite of what we did in state zero.

所以在这里住了20天。
So stayed 20 here.

我们曾经。
We were.

正确的。
Right.

停止鼓掌并向上移动。
Stop clapping and move up.

我们在这里需要做的是,如果我们实际上需要做与我们在这里所做的相反的事情,我将复制所有这些。
What we need to do here is if we need to actually do the opposite of what we did here, I will copy all of this.

我将删除与计时器有关的部分,因此,如果封盖设备来了并且应该设置为等于下降,则此处的 Karpeles 用于封盖站的移动,并且封盖设备和封盖移动设备状态都应该能够禁用在最后。
I will remove the part concerning the timer, so if capping device that device come and should be set equal to falls, that's Karpeles here for the movement of the capping station and also both the capping device and capping movement device states should be able to disabled at the end.

因此,当两者都被禁用时,这意味着封顶会再次向上移动并停止封顶。
So when both of them are disabled, this means that the capping add as as moved up again and the capping is stopped.

然后我们就处于状态 100。
Then we are in state 100.

好吧,这对我们有好处,但我们需要再次实际管理状态,因为我们在这里。
OK, this is good for us, but we need to actually manage the states again, because here when we.

当我们到达状态 50 时,我们将运行状态机 100 及之后的所有状态机。
When we get to state 50, we will run all the state machine up to 100 and after that.

州将保持一百个,所以我们实际上需要对此做点什么。
The states will remain one hundred, so we actually need to do something about it.

因此,我们在这里可以做的一件事就是在我们的车站进行封顶,我们在我们的州,在那里我们等待产品,我们需要管理这样一个事实:我们是我们需要的,有时我们只需要感觉,有时我们需要只是关心,有时我们需要两者兼而有之。
So one thing that we could do here is in our capping in our station where we in our state, where we wait for the products, we will need to manage the fact that we are we need sometimes we need only to feel, sometimes we need only to care, and sometimes we need to do both.

所以在下一个视频中,我们将继续努力。
So in the next video, we will keep on working on this.

这是一个相当长的站,但我们会进去的。
This is quite a long station, but we will get into it.